#ifndef ARMCORE_BSP_BLE_H
#define ARMCORE_BSP_BLE_H

#include "config.h"
#include <Arduino.h>
#include <BLEDevice.h>
#include <BLEServer.h>
#include <BLEUtils.h>
#include <BLE2902.h>

///______________________________________________________________________________________________

#define MAX_CHARACTERS_BTNAME 30

extern int speed_val;
extern int beep_val;
extern int voice_val;
extern void update_speed(int val);
extern void update_beep(int val);
extern void update_voice_state(bool enabled);
extern void sendFrameToVoiceModule(uint8_t command);
///______________________________________________________________________________________________
// Bluetooth类
class Bluetooth
{
private:
public:
    Bluetooth();
    int init(String = BLE_DEFAULT_NAME);
    static void setName(String);
};

extern Bluetooth ble_g;
extern BLECharacteristic *pCharacteristic;
///______________________________________________________________________________________________

/**
 * BLE功能定义
 * Service
 *
 *
 * json命令传输UUID
 *  * 获取设备UUID\name
 *  * 控制设备：reboot
 *  * play_cmd，
 *  * play_status 反馈
 *  playlist
 *  music
 *  led
 *  motor
 *  sdcard
 *
 * 文件收发UUID
 * error_msg： 上位机主动监听ble的notify
 *
 * debug：解析串口字符串命令（逗号分割，保留功能）
 * 电机控制：十六进制命令通信，保留功能
 * Music音频播放模块控制
 * RGB LED灯光控制模块
 * */

#define SERVICE_JSON_UUID "58000000-5C51-11EE-8C99-0242AC120002"
#define CHARAC_JSON_UUID "50B3F78E-5C51-11EE-8C99-0242AC120002"

#define SERVICE_FILEIO_UUID "60000000-5C5B-11EE-8C99-0242AC120002"
#define CHARAC_FILEIO_ASCII_UUID "66DE1602-5C51-11EE-8C99-0242AC120002"
#define CHARAC_FILEIO_HEX_UUID "66DE1846-5C51-11EE-8C99-0242AC120002"

#define SERVICE_DEBUG_UUID "70000000-5C5B-11EE-8C99-0242AC120002"
#define CHARAC_DEBUG_UUID "70CAB31E-5C5B-11EE-8C99-0242AC120002"
#define CHARAC_MOTOR_UUID "70CAB418-5C5B-11EE-8C99-0242AC120002"
#define CHARAC_RGB_UUID "70CAB508-5C5B-11EE-8C99-0242AC120002"
#define CHARAC_MUSIC_UUID "70CAB5F8-5C5B-11EE-8C99-0242AC120002"

///______________________________________________________________________________________________
////TODO: 判断NOTIFY 和 UART各自最佳用途

#define SERVICE_NOTIFY_UUID "10000000-5C5B-11EE-8C99-0242AC120002"
#define CHARAC_NOTIFY_MSG_UUID "105E7C98-5C5B-11EE-8C99-0242AC120002"
#define STATE_NOTIFY_UUID "87654321-4321-4321-4321-ba0987654321" // 服务UUID和特征UUID是一样的
extern BLECharacteristic *pCharac_notify_msg;
extern BLECharacteristic *pCharac_state_msg;

extern String cmdName;
extern String cmdMovelist;
///______________________________________________________________________________________________
//// BLE_UART_Service UUID
#define SERVICE_UART_UUID "6E400001-B5A3-F393-E0A9-E50E24DCCA9E"
#define CHARAC_UART_TX_UUID "6E400003-B5A3-F393-E0A9-E50E24DCCA9E"

// 使用以下的printf函数
void btprintf(const char *fmt, ...);
/// 可以直接调大上位机MTU设置 [23,500]

#define MAX_BTBUF_SIZE 20

void btprintf2(const char *fmt, ...);
///______________________________________________________________________________________________

#endif // ARMCORE_BSP_BLE_H
